import {
  ModalForm,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import React, { PropsWithChildren } from 'react';

interface UpdateFormProps {
  clssCategoryEnum: Map<number, { text: string }>;
  teacherEnum: Map<number, { text: string }>;
  adminEnum: Map<number, { text: string }>;
  jobEnum: Map<number, { text: string }>;
  children: any;
  echoRecord:API.ClassInfo
}
const UpdateForm: React.FC<PropsWithChildren<UpdateFormProps>> = ({
  teacherEnum,
  adminEnum,
  jobEnum,
  children,
  echoRecord
}) => {
  const { classMajorEnum,updateHandler } = useModel('Class.model', (model) => ({
    updateHandler: model.updateHandler,
    classMajorEnum: model.classMajorEnum,
  }));

  return (
    <ModalForm<API.Class_Add_Body>
      trigger={children}
      title="班级新增"
      initialValues={echoRecord}
      autoFocusFirstInput
      submitTimeout={2000}
      modalProps={{ destroyOnClose: true }}
      onFinish={async (values) => {
        const success = await updateHandler({
          ...values,
          cls_id: echoRecord.cls_id,
        });
        return success;
      }}
    >
      <ProFormText
        name="cls_name"
        label="班级名称"
        placeholder="请输入班级名称"
        rules={[
          { required: true, message: '员工名称为必填项!' },
          { min: 2, max: 20, message: '员工名称字数在2-20之间!' },
        ]}
      />
      <ProFormSelect
        name="cls_dic_id_major"
        label="班级专业"
        placeholder="请选择班级专业"
        valueEnum={classMajorEnum}
        rules={[{ required: true, message: '班级专业为必选项' }]}
      />
      <ProFormSelect
        name="cls_stf_id_teacher"
        label="教学老师"
        placeholder="请选择班级专业"
        valueEnum={teacherEnum}
        rules={[{ required: true, message: '班级专业为必选项' }]}
      />
      <ProFormSelect
        name="cls_stf_id_admin"
        label="教务老师"
        placeholder="请选择班级专业"
        valueEnum={adminEnum}
        rules={[{ required: true, message: '班级专业为必选项' }]}
      />
      <ProFormSelect
        name="cls_stf_id_job"
        label="就业老师"
        placeholder="请选择班级专业"
        valueEnum={jobEnum}
        rules={[{ required: true, message: '班级专业为必选项' }]}
      />
      <ProFormTextArea
        name="cls_remark"
        label="备注"
        placeholder="请输入备注..."
      />
    </ModalForm>
  );
};

export default UpdateForm;
